package com.cmw.auntapp.core.util;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

import com.cmw.auntapp.R;


/**
 * 数据库操作类
 * @author chengmingwei
 * @date 2018-08-03 23:12
 */
public class DBHelper extends SQLiteOpenHelper {
    static final String TAG = "DBHelper";

    private String dropTabSql;

    private String createTabSql;

    Context context;
    public DBHelper(Context context){
        this(context, context.getString(R.string.app_db));
    }

    public DBHelper(Context context, String dbName){
        super(context, dbName+".db", null, 1);
        this.context = context;
    }


    /**
     * 设置创建Table 表的 SQL 语句
     * @param createTabSql 创建Table 表的 SQL 语句字符串
     */
    public void setCreateTabSql(String createTabSql) {
        this.createTabSql = createTabSql;
    }

    public void setDropTabSql(String dropTabSql) {
        this.dropTabSql = dropTabSql;
    }

    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
        Log.d(TAG,"onCreate...");

//        String tabSql = context.getString(R.string.APP_MachineCfg);
//        sqLiteDatabase.execSQL(tabSql);
//        Log.d(TAG," success execute : "+tabSql);
    }


    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {

    }

    public void dropDB(){
        this.context.deleteDatabase(this.getDatabaseName());
    }
}
